#include "icebase.h"
IceBase::IceBase(QObject *parent) : QObject(parent)
{
    kModelWidth =224;
    kModelHeight = 224;
    chn =3;
    deviceID =0;
    ModelPath = "";
}

void IceBase::imgToRow(Mat frame, Row &img_Row,  bool is_rgb_shift )   //cv::Mat转FzRow;
{
    cv::Mat img;
    cv::resize(frame, img, cv::Size(kModelWidth, kModelHeight));
    int img_size = 3 * kModelWidth * kModelHeight;

    if(is_rgb_shift == 1)
    {
        char *data = (char*)img.data;
        img_Row.reserve(img_size);
        img_Row.resize(img_size);
        memcpy(&img_Row[0], data, img_size * sizeof(char));
    }

    else
    {
        int idxR = 0;
        int idxG = kModelWidth * kModelHeight;
        int idxB = idxG * 2;

        img_Row.resize(img_size);

        for (int i = 0; i < kModelWidth; ++i)  // rows
        {
            cv::Vec3b *p = img.ptr<cv::Vec3b>(i);  // ¿i¿
            char curValue;
            for (int j = 0; j < kModelHeight; ++j)  // ¿¿¿i¿¿¿¿¿
            {
                // ¿¿cell¿¿¿¿¿¿B,G,R
                curValue = p[j][2];  // RSS
                img_Row[idxR++] = curValue;

                curValue = p[j][1];  // G
                img_Row[idxG++] = curValue;

                curValue = p[j][0];  // B
                img_Row[idxB++] = curValue;
            }
        }
    }

}

/*
void IceBase::imgToRow(Mat frame, Row &img_Row)
{
          cv::Mat img ;
          cv::resize(frame, img, cv::Size(kModelWidth, kModelHeight));
          int imgSize = kModelWidth * kModelHeight * 3;

          int idxR = 0;
          int idxG = kModelWidth * kModelHeight;
          int idxB = idxG * 2;

          img_Row.resize(imgSize);

          for (int i = 0; i < kModelWidth; ++i)  // rows
          {
                  cv::Vec3b *p = img.ptr<cv::Vec3b>(i);  // ¿i¿
                  char curValue;

                  for (int j = 0; j < kModelHeight; ++j)  // ¿¿¿i¿¿¿¿¿
                  {
                          // ¿¿cell¿¿¿¿¿¿B,G,R
                          curValue = p[j][2];  // R
                         img_Row[idxR++] = curValue;

                          curValue = p[j][1];  // G
                          img_Row[idxG++] = curValue;

                          curValue = p[j][0];  // B
                          img_Row[idxB++] = curValue;
                  }
         }
}
*/

void IceBase::imgToRow(string imgfilepath, Row &img_Row)
{
          cv::Mat img = cv::imread(imgfilepath);
          cv::resize(img, img, cv::Size(kModelWidth, kModelHeight));
          int imgSize = kModelWidth * kModelHeight * 3;

          int idxR = 0;
          int idxG = kModelWidth * kModelHeight;
          int idxB = idxG * 2;

          img_Row.resize(imgSize);

          for (int i = 0; i < kModelWidth; ++i)  // rows
          {
                  cv::Vec3b *p = img.ptr<cv::Vec3b>(i);  // ¿i¿
                  char curValue;

                  for (int j = 0; j < kModelHeight; ++j)  // ¿¿¿i¿¿¿¿¿
                  {
                          curValue = p[j][2];  // R
                         img_Row[idxR++] = curValue;

                          curValue = p[j][1];  // G
                          img_Row[idxG++] = curValue;

                          curValue = p[j][0];  // B
                          img_Row[idxB++] = curValue;
                  }
         }
}
